﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sy4_2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            listBox1.Items.Add("VB程序设计");
            listBox1.Items.Add("C#程序设计");
            listBox1.Items.Add("数据库技术与应用");
            listBox1.Items.Add("硬件技术基础");
            listBox1.Items.Add("Web程序设计");
            listBox1.Items.Add("多媒体技术与应用");
            listBox1.Items.Add("网络技术与应用");
            listBox1.Items.Add("软件工程");
            listBox1.Items.Add("大学计算机基础");
            listBox1.Sorted = true;
            listBox2.Sorted = true;
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBox1.Text != "")
            {
                if (listBox2.Items.Count >= 5)
                {
                    MessageBox.Show("对不起，您最多只能选5门课！");
                }
                else
                {
                    listBox2.Items.Add(listBox1.Text);
                    listBox1.Items.RemoveAt(listBox1.SelectedIndex);
                }
            }
        }

        private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBox2.Text != "")
            {
                listBox1.Items.Add(listBox2.Text);
                listBox2.Items.RemoveAt(listBox2.SelectedIndex);
            }
        }
    }
}
